package tk.xboot.boot.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Application event to be handle.
 *
 * @author Asin Liu
 * @version 1.0.0
 * @since 1.0.0
 */


@Component
public class ApplicationEventInit {
    Logger log = LoggerFactory.getLogger(ApplicationEventInit.class);
    @EventListener(ApplicationStartedEvent.class)
    public void run() throws IOException {
        log.info(">>> ApplicationStartedEvent fired!");
        ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader());
        Resource[] resources = patternResolver.getResources("classpath*:META-INF/spring.xml");
        System.out.println("***********");
        for(Resource resource : resources) {
            System.out.println(resource.getDescription());
        }

        log.info(">>> ApplicationStartedEvent ended. ");
    }
}
